import LayVmodelBase from "./LayVmodelBase.js"
import { logger, tools, runtime } from "./tools.js";


/**Layui 进度条(单向) */
class LayProgressVmodel extends LayVmodelBase {
    constructor(elem) {
        super(elem);
        this.transDirection = "fromValue";
        this.ensureFilter();
    }

    /**[override] */
    viewModelInit() {
        super.viewModelInit();
        this.vm.value = ko.observable(0);
    }

    /**[override] */
    onDisabledChange(disabled) {
        return;
    }

    /**[override] */
    init() {
        if (!super.init()) return;
        var tis = this;
        let element = tools.laymod('element');
        //订阅value变化
        this.vm.value.subscribe((newValue) => {
            $(this.element).val(newValue);
            element.progress(tis.layFilter, newValue + "%");
            $(tis.element).children(".layui-progress-bar").attr("lay-percent", newValue + "%");
        });

        $(tis.element).children(".layui-progress-bar").attr("lay-percent", this.vm.value() + "%");
        
        element.render('progress', tis.layFilter);
        element.progress(tis.layFilter, this.vm.value() + "%");
        
        
        this.inited = true;
    }
}


export default LayProgressVmodel;